//InsureOrderModel
//2020-08-25 09:59:58

package models

import (
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/models/base"
	"git.900sui.cn/kc/kcgin/orm"
)

//表结构体
type InsureOrderModel struct {
	Model *base.Model
	Field InsureOrderModelField
}

//表字段
type InsureOrderModelField struct {
	T_table           string `default:"insure_order"`
	F_id              string `default:"id"`
	F_order_sn        string `default:"order_sn"`
	F_pay_sn          string `default:"pay_sn"`
	F_insure_id       string `default:"insure_id"`
	F_total_amount    string `default:"total_amount"`
	F_amount          string `default:"amount"`
	F_create_time     string `default:"create_time"`
	F_pay_channel     string `default:"pay_channel"`
	F_clearing_id     string `default:"clearing_id"`
	F_clearing_status string `default:"clearing_status"`
}

//初始化
func (i *InsureOrderModel) Init(ormer ...orm.Ormer) *InsureOrderModel {
	functions.ReflectModel(&i.Field)
	i.Model = base.NewModel(i.Field.T_table, ormer...)
	return i
}

//新增数据
func (i *InsureOrderModel) Insert(data map[string]interface{}) int {
	result, _ := i.Model.Data(data).Insert()
	return result
}

// 更新状态
func (i *InsureOrderModel) UpdateByClingStatus(payChannel, clearingStatus int, clearingId string, data map[string]interface{}) (int, error) {
	return i.Model.Where(map[string]interface{}{
		i.Field.F_pay_channel:     payChannel,
		i.Field.F_clearing_id:     clearingId,
		i.Field.F_clearing_status: clearingStatus,
	}).Data(data).Update()
}
